package logic

import (
	"context"
	"major-six/major/goods/goods"

	"major-six/major/api/internal/svc"
	"major-six/major/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsPageLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsPageLogic {
	return &GoodsPageLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsPageLogic) GoodsPage(req *types.GoodsPageReq) (resp *types.Response, err error) {
	goodslist, err := l.svcCtx.GoodsRpc.GoodsPage(l.ctx, &goods.GoodsPageRequest{
		Page:     int64(req.Page),
		PageSize: int64(req.PageSize),
	})
	if err != nil {
		return nil, err
	}

	return &types.Response{
		Code: 0,
		Msg:  "商品数据分页展示",
		Data: map[string]interface{}{
			"list": goodslist,
		},
	}, nil
}
